package service

import (
	"encoding/json"

	"gitee.com/nggs/protoactor-go/actor"
)

const (
	PayloadNil = -1
)

////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
type Instance struct {
	PID       actor.PID
	PprofAddr string
	Extra     map[string]interface{}
}

func NewInstance() (i *Instance) {
	i = &Instance{
		Extra: map[string]interface{}{},
	}
	return
}

func (i Instance) IsEmpty() bool {
	return i.PID.Address == "" || i.PID.Id == ""
}

func (i Instance) String() string {
	ba, _ := json.Marshal(i)
	return string(ba)
}

////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
type Info struct {
	Config     IConfig
	ConfigData []byte
	Instance   *Instance
	Payload    int
}

func NewInfo(config IConfig, configData []byte, id int) *Info {
	s := &Info{
		Config:     config,
		ConfigData: configData,
		Payload:    PayloadNil,
	}
	s.Config.SetID(id)
	return s
}

func (i Info) IsEmpty() bool {
	return i.Config == nil
}
